home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / rlib / lyap < prev    next >
Text File  |  1994-09-23  |  983b  |  57 lines

  1. //-------------------------------------------------------------------//
  2. // lyap.r:
  3. //
  4. // Syntax:    lyap ( A , B , C )
  5. //        lyap ( A ,   , C )
  6. //
  7. // Description:
  8. //
  9. // lyap solves the general form of the Lyapunov (Sylvester) equation:
  10. //
  11. //    A*X + X*B = -C
  12. //
  13. // To solve the special form of the Lyapunov equation:
  14. //
  15. //    A*X + X*A' = -C
  16. //
  17. // Skip the second argument when using lyap (`lyap (A,,C)').
  18.  
  19. // See Also: schur, sylv
  20. //-------------------------------------------------------------------//
  21.  
  22. lyap = function ( A, B, C )
  23. {
  24.   if (!exist (B)) 
  25.   { 
  26.     B = A';    // Solve the special form: A*X + X*A' = -C
  27.   }
  28.  
  29.   if ((A.nr != A.nc) || (B.nr != B.nc) || (C.nr != A.nr) || (C.nc != B.nr)) 
  30.   {
  31.     error ("Dimensions do not agree.");
  32.   }
  33.  
  34.   //
  35.   // Schur decomposition on A and B
  36.   //
  37.  
  38.   sa = schur (A);
  39.   sb = schur (B);
  40.  
  41.   //
  42.   // transform C
  43.   //
  44.  
  45.   tc = sa.z' * C * sb.z;
  46.  
  47.   X = sylv (sa.t, sb.t, tc);
  48.  
  49.   //
  50.   // Undo the transformation
  51.   //
  52.  
  53.   X = sa.z * X * sb.z';
  54.  
  55.   return X;
  56. };
  57.